#include "pcrActionBarGuide.h"

PCRActionBarGuide::PCRActionBarGuide(PCRState *state, QWidget* parent) : pState(state)
{
    this->setParent(parent);

    // 指导意见按钮
    _button_pageData = new QPushButton("分析数据", this);
    _button_pagePlan = new QPushButton("检测方案", this);
    _button_count = new QPushButton("总数: 4", this);
    _button_miniSTR = new QPushButton("mini-STR: 0", this);
    _button_YSTR = new QPushButton("Y-STR: 0", this);
    _button_dilute = new QPushButton("需稀释样本数量: 0", this);
    _layout = new QHBoxLayout(this);

    QFont font;
    font.setItalic(true);
    font.setUnderline(true);
    _button_count   ->setFont(font);
    _button_miniSTR ->setFont(font);
    _button_YSTR    ->setFont(font);
    _button_dilute  ->setFont(font);


    this->setLayout(_layout);
    _layout->setSpacing(0);
    _layout->addWidget(_button_pageData);
    _layout->addWidget(_button_pagePlan);

    _layout->addWidget(_button_count);
    _layout->addWidget(_button_miniSTR);
    _layout->addWidget(_button_YSTR);
    _layout->addWidget(_button_dilute);

    _button_pageData->setFixedSize(QSize(120, 40));
    _button_pagePlan->setFixedSize(QSize(120, 40));
    _button_count   ->setFixedSize(QSize(80 , 40));
    _button_miniSTR ->setFixedSize(QSize(120, 40));
    _button_YSTR    ->setFixedSize(QSize(110, 40));
    _button_dilute  ->setFixedSize(QSize(180, 40));


#ifdef Q_OS_ANDROID
    _button_count   ->setStyleSheet("background: rgb(14,114,212); color: white;");
    _button_miniSTR ->setStyleSheet("background: rgb(14,114,212); color: white;");
    _button_YSTR    ->setStyleSheet("background: rgb(14,114,212); color: white;");
    _button_dilute  ->setStyleSheet("background: rgb(14,114,212); color: white;");
#else
    _button_count   ->setStyleSheet("background: rgba(255,255,255,0); color: white;");
    _button_miniSTR ->setStyleSheet("background: rgba(255,255,255,0); color: white;");
    _button_YSTR    ->setStyleSheet("background: rgba(255,255,255,0); color: white;");
    _button_dilute  ->setStyleSheet("background: rgba(255,255,255,0); color: white;");
#endif

    connect(_button_pageData, SIGNAL(clicked()), this, SLOT(on_pageData_clicked()));
    connect(_button_pagePlan, SIGNAL(clicked()), this, SLOT(on_pagePlan_clicked()));
    connect(_button_count, SIGNAL(clicked()), this, SLOT(on_count_clicked()));
    connect(_button_miniSTR, SIGNAL(clicked()), this, SLOT(on_miniSTR_clicked()));
    connect(_button_YSTR, SIGNAL(clicked()), this, SLOT(on_YSTR_clicked()));
    connect(_button_dilute, SIGNAL(clicked()), this, SLOT(on_dilute_clicked()));

}

void PCRActionBarGuide::showEvent(QShowEvent* event){
    this->refresh();
}

void PCRActionBarGuide::refresh(){

    this->setUpdatesEnabled(false);
    if(pState->currentPage == PCRState::GUIDE_DATA){
        _button_YSTR->hide();
        _button_count->hide();
        _button_dilute->hide();
        _button_miniSTR->hide();
        _button_pageData->setStyleSheet("background: white; color: blue; border: 1px solid #FFFFFF;");
        _button_pagePlan->setStyleSheet("background: rgba(255,255,255,0); color: white; border: 1px solid #FFFFFF;");
    }else if(pState->currentPage == PCRState::GUIDE_PLAN){
        _button_YSTR   ->show();
        _button_count  ->show();
        _button_dilute ->show();
        _button_miniSTR->show();

        _button_YSTR   ->setText("Y-STR:" +         QString::number(pState->guideYSTR));
        _button_count  ->setText("总数:" +            QString::number(pState->guideSum));
        _button_dilute ->setText("需稀释样本数量:" +   QString::number(pState->guideDilute));
        _button_miniSTR->setText("mini-STR:" +      QString::number(pState->guideMiniSTR));
        _button_pagePlan->setStyleSheet("background: white; color: blue; border: 1px solid #FFFFFF;");
        _button_pageData->setStyleSheet("background: rgba(255,255,255,0); color: white; border: 1px solid #FFFFFF;");
    }
    _button_count   ->setStyleSheet("background: rgb(14,114,212); color: white; border:0px;");
    _button_miniSTR ->setStyleSheet("background: rgb(14,114,212); color: white; border:0px;");
    _button_YSTR    ->setStyleSheet("background: rgb(14,114,212); color: white; border:0px;");
    _button_dilute  ->setStyleSheet("background: rgb(14,114,212); color: white; border:0px;");

    this->setUpdatesEnabled(true);
}

void PCRActionBarGuide::on_pageData_clicked(){
    pState->currentPage = PCRState::GUIDE_DATA;
    pState->emitPageChanged();
}

void PCRActionBarGuide::on_pagePlan_clicked(){
    pState->currentPage = PCRState::GUIDE_PLAN;
    pState->emitPageChanged();
}

void PCRActionBarGuide::on_YSTR_clicked(){
    pState->guidePage = 3;
    pState->emitGuidePageChanged();
}

void PCRActionBarGuide::on_count_clicked(){
    pState->guidePage = 1;
    pState->emitGuidePageChanged();
}

void PCRActionBarGuide::on_miniSTR_clicked(){
    pState->guidePage = 4;
    pState->emitGuidePageChanged();
}

void PCRActionBarGuide::on_dilute_clicked(){
    pState->guidePage = 5;
    pState->emitGuidePageChanged();
}


void PCRActionBarGuide::on_guideNumChanged(){

    qDebug("bar改变Num");

}




